﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using PAMD.Business.Models.Models;
using PAMD.Data.Ajax.Services.Common;

namespace PAMD.Data.Ajax.Services.Controllers
{
    [Export]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class SearchMapController : ApiController
    {
        public HttpResponseMessage Get(string q)
        {
            string pageContent = string.Empty;
            PlaceResponse jsonObj = null;
            try
            {
                WebRequest request = WebRequest.Create(new Uri(Constants.GoogleMapAuto + q + Constants.Query));
                WebResponse response = request.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream());
                // Read the entire stream content:
                pageContent = reader.ReadToEnd();
                response.Close();
            }
            catch (Exception ex)
            {
                jsonObj = new PlaceResponse { status = "ERROR", predictions = new List<Prediction>() };
            }

            HttpResponseMessage message = new HttpResponseMessage();
            message.StatusCode = HttpStatusCode.OK;
            message.Content = new StringContent(pageContent);
            return message;
        }

        // GET api/values/5
        public string Get(int id)
        {
            return "value";
        }

        // POST api/values
        public void Post([FromBody]string value)
        {
        }

        // PUT api/values/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE api/values/5
        public void Delete(int id)
        {
        }
    }
}